#include "SimpleEncode.h"
#include "foc_utils.h"
SimpleEncode_t inc_encode_A;
void SimpleEncode_Init(SimpleEncode_t *handle,float _ppr)
{
	handle->cpr=_ppr;
}
void SimpleEncode_Hal(SimpleEncode_t *handle,EncodeGetPulse f)
{
	handle->getPulse=f;
}
void update() {
	
}
float SimpleEncode_getAngle(SimpleEncode_t *handle)
{
  return  _2PI * (handle->getPulse()) / ((float)handle->cpr);
}
/*
	Shaft angle calculation
*/
float SimpleEncode_getSensorAngle(SimpleEncode_t *handle)
{
  return SimpleEncode_getAngle(handle);
}
// TODO: numerical precision issue here if the pulse_counter overflows the angle will be lost
float SimpleEncode_getMechanicalAngle(SimpleEncode_t *handle)
{
  return  _2PI * ((handle->getPulse()) % ((int) handle->cpr)) / ((float)handle->cpr);
}
double SimpleEncode_getPreciseAngle(SimpleEncode_t *handle)
{
  return  _2PI * (handle->getPulse()) / ((double)handle->cpr);
}
int SimpleEncode_getFullRotations(SimpleEncode_t *handle)
{
  return  handle->getPulse() / (int)handle->cpr;
}
